1.8
文件操作
写文件：指定文件名、指定打开方式是写文件、读操作

#include<iostream>
#include<fstream>
using namespace std;

int main()
{	
	ofstream f;
	f.open("1-8.data",ios::out);
	f << "hello";
	f.close();
	ifstream w;
	w.open("1-8.data", ios::in);
	char a[1024] = {0};
	while (w >> a)
	{
		cout << a;
	}
	w.close();
	return 0;
}
STL
标准模版库

需要做的：记住STL的类，哪些类做哪些事，记住函数

学会查询使用文档MSDN

vector
容器，类似数组

他比数组区别于可以无限扩容，有方便操作的函数来维护数据

#include<iostream>
#include<fstream>
#include<vector>
using namespace std;

int main()
{	
	vector<int> v;
	v.push_back(1);
	v.push_back(2);
	v.push_back(3);
	int size = v.size();
	for (int i = 0; i < size; i++)
	{
		cout << v[i];
	}
	return 0;
}
#include<iostream>
#include<fstream>
#include<vector>
using namespace std;

int main()
{	
	vector<int> v;
	v.push_back(1);
	v.push_back(2);
	v.push_back(3);
	vector<int>::iterator begin = v.begin();
	vector<int>::iterator end = v.end();
	while(begin != end)
	{
		cout << *begin;
		begin++;
	}
	return 0;
}
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

void Print(int a)
{
	cout << a;
}

int main()
{	
	vector<int> v;
	v.push_back(rand());
	v.push_back(rand());
	v.push_back(rand());
	for_each (v.begin(), v.end(), Print);
	return 0;
}
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

class People
{
public:
	int id;
	string name;
public:
	People(int i, string n)
	{
		id = i;
		name = n;
	}
};

void Print(People p)
{
	cout << p.id << p.name;
}

int main()
{	
	vector <People> v;
	People p(1, "x");
	v.push_back(p);
	People p1(1, "x");
	v.push_back(p1);
	People p2(1, "x");
	v.push_back(p2);
	for_each (v.begin(), v.end(), Print);
	return 0;
}
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

void print(int a)
{
	cout << a;
}

int main()
{	
	vector <int> v = {4,2,3,1};
	sort(v.begin(),v.end());
	for_each (v.begin(), v.end(), print);
	return 0;
}
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

class People
{
public:
	int id;
	string name;
public:
	People(int i, string n)
	{
		id = i;
		name = n;
	}
};

void print(People p)
{
	cout << p.id << p.name;
}

bool CaP(People a1, People a2)
{
	return a1.id < a2.id;
}

int main()
{	
	vector < People > v = { {1,"n1"},{2,"n2"},{3,"n3"}};
	sort(v.begin(),v.end(),CaP);
	for_each (v.begin(), v.end(), print);
	return 0;
}
list
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include <list>
using namespace std;

int main()
{	
	list<int> a;
	a.push_back(3);
	a.push_front(2);
	a.push_front(1);
	for(list<int>::iterator  it=a.begin();it!=a.end();it++)
	{
		cout << *it;
	}
    for (auto it = a.begin(); it != a.end(); it++)
	{
		cout << *it;
	}
	return 0;
}
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include <list>
using namespace std;

void Print(int a)
{
	cout << a;
}

int main()
{	
	list<int> a;
	a.push_back(3);
	a.push_front(1);
	a.push_front(2);
	a.sort();
	for_each(a.begin(), a.end(), Print);
	return 0;
}